package com.genexususa.eo.bing.data.wsSubclasses;

import com.genexususa.eo.bing.CampaignManagementServiceClasses.*;
import com.genexususa.eo.bing.data.GxItemException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class GxCallAdExtension extends CallAdExtension {
    private long gxCampaignId;
    private long gxId;

    public      GxCallAdExtension(Element element) throws IllegalArgumentException, GxItemException {

        // AdExtension2 parameters

        if (element.getElementsByTagName("GxCampaignId").getLength() > 0 &&
                element.getElementsByTagName("GxCampaignId").item(0).getChildNodes().getLength() > 0 &&
                Long.valueOf(((Node)element.getElementsByTagName("GxCampaignId").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.gxCampaignId = Long.valueOf(((Node)element.getElementsByTagName("GxCampaignId").item(0).getChildNodes().item(0)).getNodeValue());
        } else {
            throw new GxItemException("Missing external Campaign id");
        }
        if (element.getElementsByTagName("GxCallAdExtensionId").getLength() > 0 &&
                element.getElementsByTagName("GxCallAdExtensionId").item(0).getChildNodes().getLength() > 0 &&
                Long.valueOf(((Node)element.getElementsByTagName("GxCallAdExtensionId").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.gxId = Long.valueOf(((Node)element.getElementsByTagName("GxCallAdExtensionId").item(0).getChildNodes().item(0)).getNodeValue());
        } else {
            throw new GxItemException("Missing external CallAdExtension id");
        }
        if (element.getElementsByTagName("GxCallAdExtensionId").getLength() > 0 &&
            element.getElementsByTagName("GxCallAdExtensionId").item(0).getChildNodes().getLength() > 0 &&
            Long.valueOf(((Node)element.getElementsByTagName("GxCallAdExtensionId").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.gxId = Long.valueOf(((Node)element.getElementsByTagName("GxCallAdExtensionId").item(0).getChildNodes().item(0)).getNodeValue());
        } else {
            throw new GxItemException("Missing external CallAdExtension id");
        }
        if (element.getElementsByTagName("BingCallAdExtensionId").getLength() > 0 &&
            element.getElementsByTagName("BingCallAdExtensionId").item(0).getChildNodes().getLength() > 0 &&
            Long.valueOf(((Node)element.getElementsByTagName("BingCallAdExtensionId").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.setId(Long.valueOf(((Node) element.getElementsByTagName("BingCallAdExtensionId").item(0).getChildNodes().item(0)).getNodeValue()));
        }
        if (element.getElementsByTagName("Status").getLength() > 0 &&
            element.getElementsByTagName("Status").item(0).getChildNodes().getLength() > 0) {
            if (((Node) element.getElementsByTagName("Status").item(0).getChildNodes().item(0)).getNodeValue().equals("A")) {
                this.setStatus(AdExtensionStatus.Active);
            } else if (((Node) element.getElementsByTagName("Status").item(0).getChildNodes().item(0)).getNodeValue().equals("D")) {
                this.setStatus(AdExtensionStatus.Deleted);
            }
        }
        if (element.getElementsByTagName("Type").getLength() > 0 &&
            element.getElementsByTagName("Type").item(0).getChildNodes().getLength() > 0) {
            this.setType(((Node) element.getElementsByTagName("Type").item(0).getChildNodes().item(0)).getNodeValue());
        }
        if (element.getElementsByTagName("Version").getLength() > 0 &&
            element.getElementsByTagName("Version").item(0).getChildNodes().getLength() > 0 &&
            Integer.valueOf(((Node)element.getElementsByTagName("Version").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.setVersion(Integer.valueOf(((Node) element.getElementsByTagName("Version").item(0).getChildNodes().item(0)).getNodeValue()));
        }

        // CallAdExtension parameters

        if (element.getElementsByTagName("CountryCode").getLength() > 0 &&
            element.getElementsByTagName("CountryCode").item(0).getChildNodes().getLength() > 0) {
            this.setCountryCode(((Node) element.getElementsByTagName("CountryCode").item(0).getChildNodes().item(0)).getNodeValue());
        }
        if (element.getElementsByTagName("IsCallOnly").getLength() > 0 &&
            element.getElementsByTagName("IsCallOnly").item(0).getChildNodes().getLength() > 0) {
            this.setIsCallOnly(Boolean.valueOf(((Node) element.getElementsByTagName("IsCallOnly").item(0).getChildNodes().item(0)).getNodeValue()));
        }
        if (element.getElementsByTagName("IsCallTrackingEnabled").getLength() > 0 &&
            element.getElementsByTagName("IsCallTrackingEnabled").item(0).getChildNodes().getLength() > 0) {
            this.setIsCallTrackingEnabled(Boolean.valueOf(((Node) element.getElementsByTagName("IsCallTrackingEnabled").item(0).getChildNodes().item(0)).getNodeValue()));
        }
        if (element.getElementsByTagName("PhoneNumber").getLength() > 0 &&
            element.getElementsByTagName("PhoneNumber").item(0).getChildNodes().getLength() > 0) {
            this.setPhoneNumber(((Node) element.getElementsByTagName("PhoneNumber").item(0).getChildNodes().item(0)).getNodeValue());
        }
        if (element.getElementsByTagName("RequireTollFreeTrackingNumber").getLength() > 0 &&
            element.getElementsByTagName("RequireTollFreeTrackingNumber").item(0).getChildNodes().getLength() > 0) {
            this.setRequireTollFreeTrackingNumber(Boolean.valueOf(((Node) element.getElementsByTagName("RequireTollFreeTrackingNumber").item(0).getChildNodes().item(0)).getNodeValue()));
        }
    }

    public long getGxId() {
        return gxId;
    }

    public void setGxId(long gxId) {
        this.gxId = gxId;
    }

    public long getGxCampaignId() {
        return gxCampaignId;
    }

    public void setGxCampaignId(long gxCampaignId) {
        this.gxCampaignId = gxCampaignId;
    }
}
